import { setStorage } from '../utils/auth'
// 主题色常量
const GRAY_THEME_COLOR = '#495060'
const COLOR = '#2d8cf0'
const WHITE_THEME_COLOR = '#fff'

const actions = {}
const mutations = {
  // 初始化主题
  INIT_THEME(state, theme) {
    state.theme = theme
    setStorage('theme', state.theme)
  },
  // 改变主题
  CHANGE_THEME(state, theme) {
    const color = theme.color
    // 灰色主题
    if (theme.icon.includes('mian')) {
      state.theme = { bgColor: GRAY_THEME_COLOR, fontColor: WHITE_THEME_COLOR }
    } else {
      // 白色主题
      state.theme = { bgColor: WHITE_THEME_COLOR, fontColor: GRAY_THEME_COLOR }
    }
    state.theme.color = color
    setStorage('theme', state.theme)
    // 切换主题时，刷新当前页面
    location.reload()
  },
}
const state = {
  // 主题对象，默认灰色主题
  theme: {
    bgColor: GRAY_THEME_COLOR,
    fontColor: WHITE_THEME_COLOR,
    color: COLOR,
  },
}

export default {
  namespaced: true,
  actions,
  mutations,
  state,
}
